//
//  MTFeedBackVC.m
//  met
//
//  Created by 李晓俊 on 2019/6/25.
//  Copyright © 2019 李晓俊. All rights reserved.
//

#import "MTFeedBackVC.h"

#import "CustomTextView.h"

@interface MTFeedBackVC ()
@property (weak, nonatomic) IBOutlet CustomTextView *textView;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *height;

@end

@implementation MTFeedBackVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = KBackColor;
    self.navigationItem.title = @"意见反馈";
    self.textView.text = @"";
    self.textView.textColor = KBlackColor;
    
    self.textView.placehFont = CLRudeCircleTextFont(15);
    self.textView.placehTextColor = TextDescribeColor;
    self.textView.promptFont = CLRudeCircleTextFont(12);
    self.textView.promptTextColor = TextTiTleColor;
    self.textView.textColor = KBlackColor;
    self.textView.font =  CLRudeCircleTextFont(15);
//    self.textView.promptFrameMaxX = 20;
    self.textView.interception = YES;
    
    self.textView.placehText = @"请输入您的宝贵建议或者遇到的问题...";
    self.textView.textLength = 200;
    
    self.bgView.layer.cornerRadius = 5;
    self.bgView.layer.masksToBounds = YES;
    self.bgView.layer.borderWidth = 2.0f;
    self.bgView.layer.borderColor = KBlackColor.CGColor;
    
    self.height.constant = NavHeight + 20;
    [self.view needsUpdateConstraints];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.textView becomeFirstResponder];
}
- (IBAction)feddbackClick:(UIButton *)sender {
    [self.view endEditing:YES];
    if (self.textView.text.length == 0) {
        [self.view maketishiToast:@"请输入内容"];
        return;
    }
    AccountService *acc = [AccountService getObject];
    acc.httpRequestResultBlock = ^(id data,int code){
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (code == 1) {
            [self.view makeToast:@"提交反馈成功,平台将会在24小时之内给出回复"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
            
        }else {
            [self.view makeToast:data];
        }
    };
    if ([self.isYinji isEqualToString:@"1"]) {
        [acc imprintReportAdd:self.textView.text imprintId:self.yinjiId];
    }else {
        [acc feedbackInsert:self.textView.text];
    }
}

@end
